package nl.scalasim.util

/**
 * An accumulator accumulates calls and counts them modulo <code>speed</code>.
 * Whenever the count of an accumulator is larger than <code>speed</code>,
 * it is stored in <code>overflow</code>.
 *
 * @author Yigal Duppen
 * @since Oct 4, 2010
 */
case class Accumulator(speed: Int, count: Int = 0, overflow: Int = 0) {

  /**
   * Accumulates one call and returns a new accumulator containing the
   * new values; overflow is reset. 
   */
  def accumulate(): Accumulator = Accumulator(speed, (count + 1) % speed, (count + 1) / speed)

}